package com.ygqh.baby.service.impl;
import java.util.List;
import  com.ygqh.baby.ao.QueryInfo;
import  com.ygqh.baby.ao.ResultSet;
import  com.ygqh.baby.po.AdminMarketingContract;
import  com.ygqh.baby.mapper.AdminMarketingContractMapper;
import  com.ygqh.baby.service.AdminMarketingContractService;
import  org.springframework.util.Assert;
import java.util.Arrays;
import  org.springframework.stereotype.Service;
import  org.springframework.beans.factory.annotation.Autowired;

import  com.ygqh.baby.po.AdminMarketingContractExample;
import  com.ygqh.baby.ao.DataStatus;

@Service
public class AdminMarketingContractServiceImpl implements AdminMarketingContractService{
	
	@Autowired
	private AdminMarketingContractMapper adminMarketingContractMapper;
	
	@Override
	public List<AdminMarketingContract> find() {
		AdminMarketingContractExample example = new AdminMarketingContractExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return adminMarketingContractMapper.selectByExample(example);
	}

	@Override
	public int findCount() {
		AdminMarketingContractExample example = new AdminMarketingContractExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return adminMarketingContractMapper.countByExample(example);
	}

	@Override
	public AdminMarketingContract findById(Long id) {
		return adminMarketingContractMapper.selectByPrimaryKey(id);
	}


	

	@Override
	public int save(AdminMarketingContract adminMarketingContract) {
		return adminMarketingContractMapper.insertSelective(adminMarketingContract);
	}

	@Override
	public int update(AdminMarketingContract adminMarketingContract) {
		return adminMarketingContractMapper.updateByPrimaryKeySelective(adminMarketingContract);
	}

	@Override
	public ResultSet<AdminMarketingContract> search(QueryInfo queryInfo,String q) {
		List<AdminMarketingContract>  list =  adminMarketingContractMapper.selectSuper(queryInfo, q);
		int count = adminMarketingContractMapper.countSuper(q);
		ResultSet<AdminMarketingContract> resultSet = new ResultSet<AdminMarketingContract>(count,list);
		return resultSet;
	}

	@Override
	public int deleteSoft(Long[] ids) {
		Assert.notEmpty(ids);
		AdminMarketingContractExample example = new AdminMarketingContractExample();
		example.createCriteria().andIdIn(Arrays.asList(ids));
		AdminMarketingContract record = new AdminMarketingContract();
		record.setStatus(DataStatus.Delete);

		return adminMarketingContractMapper.updateByExampleSelective(record, example);
	}
	
	@Override
	public int deleteSoft(Long id) {
		return this.deleteSoft(new Long[]{id});
	}

	@Override
	public int saveOrUpdate(AdminMarketingContract adminMarketingContract) {
		int r = 0;
		if(adminMarketingContract.getId() != null) {
			r = this.update(adminMarketingContract);
		}else {
			r = this.save(adminMarketingContract);
		}
		return r;
	}

}

